#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
//	extern char** environ;
//	putenv("MYENV=6666666");

	pid_t id = fork();
	if(id < 0)
	{
		printf("进程创建失败\n");
		exit(1);
	}
	else if(id == 0)
	{
		//子进程
		printf("子进程替换进程前\n");
		//int ret = execl("/usr/bin/ls","ls","-a","-l",NULL);
		//int ret = execlp("ls","ls","-a","-l",NULL);
		//char* const myargv[] = { "ls" , "-a" , "-l" , NULL };
		//int ret = execv("/usr/bin/ls",myargv);
		//char* const myargv[] = { "ls" , "-a" , "-l" , NULL };
		//int ret = execvp("ls",myargv);
		//execl("./other","other",NULL);
	//	execl("/usr/bin/bash","bash","python.sh",NULL);
	//	if(ret == -1)
	//	{
	//		printf("进程替换失败\n");
	//	}
	//	execlp("./other","other",NULL,);		
	//	char* const myenv[] = {"MYENV1=123","MYENV2=456","MYENV3=789",NULL};
	//	char* const myargv[] = {"other","-a","-b",NULL};
	//	execve("./other",myargv,myenv);		
		int ret = execl("/usr/bin/bash","bash","python.py",NULL);
		if(ret == -1)
		{
			printf("进程替换失败\n");
		}
		printf("子进程替换进程后\n");
		exit(1);
	//	int cnt = 5;
	//	while(cnt--)
	//	{
	//		printf("子进程正在进行，pid = %d,ppid = %d,cnt = %d\n",getpid(),getppid(),cnt);
	//		sleep(1);
	//	}
	}
	else
	{
		printf("父进程正常执行\n");
		pid_t ret = waitpid(id,NULL,0);
		if(ret == id)
		{
			printf("等待成功\n");
		}
		//父进程
		//int cnt = 10;
		//while(cnt--)
		//{
		//	printf("父进程正在进行，pid = %d,ppid = %d,cnt = %d\n",getpid(),getppid(),cnt);
		//	sleep(1);
		//}
		//int status = 0;
		//pid_t ret = waitpid(id,&status,0);
		//if(ret == id)
		//{
		//	printf("等待成功,ret = %d\n",ret);
		//}
		//sleep(5);
	}
	return 0;
}
